# -*- coding:utf-8 -*-

__author__ = 'chendaqing'

"""
商城模块的总入口模块,包括与网站有关的模板、国际化、配置信息等等的初始化的地方
"""

from flask import Flask


__all__ = ["create_app"]

DEFAULT_APP_NAME = "community"

DEFAULT_MODULES = (
#(views.post, "/post"),
#(views.user, "/user"),
#(views.comment, "/comment"),
#(views.account, "/acct"),
#(views.feeds, "/feeds"),
#(views.openid, "/openid"),
#(views.api, "/api"),
)

def create_app(config=None, app_name=None, modules=None):

	if app_name is None:
		app_name = DEFAULT_APP_NAME

	if modules is None:
		modules = DEFAULT_MODULES

	app = Flask(app_name)
	app.config.from_object('websiteconfig')

	#基本的配置信息
	configure_app(app, config)

	configure_modules(app, modules)

	return app


def configure_app(app, config):
	if config is not None:
		app.config.from_object(config)
	app.config.from_envvar('APP_CONFIG', silent=True)

def configure_modules(app, modules):
	for module, urlprefix in modules:
		app.register_blueprint(module, url_prefix=urlprefix)#url_prefix
		print module.__dict__

if __name__ == "__main__":
	app = create_app()
	app.run()
